package com.demo.interceptor;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Component;

import java.util.Properties;

@Component
@Intercepts({@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class})})
public class ExecutorInterceptor implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println("ExecutorInterceptor-invocation---前置");
        Object proceed = invocation.proceed();
        System.out.println("ExecutorInterceptor-invocation---后置");
        return proceed;
    }

//    @Override
//    public Object plugin(Object target) {
//        System.out.println("ExecutorInterceptor-plugin---target：" + target.getClass());
//        return Plugin.wrap(target, this);
//    }

    @Override
    public void setProperties(Properties properties) {
        System.out.println("ExecutorInterceptor-setProperties---");
    }
}
